﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.StopZero.CApStopZeroLocationValidator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.StopZero.Resources;
using System;
using System.Collections.Generic;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.StopZero;

public class CApStopZeroLocationValidator : CApStopZeroAdditionalInfoCachingValidator
{
  private readonly Func<ITxRoboticLocationOperation> _getOpositeLocation;

  public CApStopZeroLocationValidator(
    Func<ITxRoboticLocationOperation> getOppositeLocation)
    : base(StopZeroStringTable.NotRoboticLocationOperationError)
  {
    this._getOpositeLocation = getOppositeLocation;
  }

  protected override string GetCachedValidationError(ITxObject obj)
  {
    if (!(obj is ITxRoboticLocationOperation location))
      return StopZeroStringTable.NotRoboticLocationOperationError;
    ITxRobot assignedRobot = CApStopZeroUtilities.GetAssignedRobot(location);
    if (assignedRobot == null)
      return StopZeroStringTable.NoRobotError;
    if (!CApStopZeroUtilities.IsStopZeroCapable(assignedRobot))
      return StopZeroStringTable.NoStopZeroRobotError;
    List<ITxObject> activeTools = CApStopZeroUtilities.GetActiveTools(location);
    return activeTools == null || activeTools.Count == 0 ? StopZeroStringTable.NoToolError : (string) null;
  }

  protected override string GetNonCachedValidationError(ITxObject obj)
  {
    if (!(obj is ITxRoboticLocationOperation first))
      return StopZeroStringTable.NotRoboticLocationOperationError;
    ITxRoboticLocationOperation second = this._getOpositeLocation();
    if (second == first)
      return StopZeroStringTable.SameLocationError;
    return second != null && !CApStopZeroUtilities.AreInSameOperation(first, second) ? StopZeroStringTable.DifferentOperationsError : (string) null;
  }
}
